from django.shortcuts import render
from django.core import serializers

# Create your views here.

from django.shortcuts import render
from django.http import JsonResponse
from django.db.models import Q
from ..models import *
import datetime
import math


# 教师管理
def user_list(request):
    data_list = UserMsg.objects.all()
    return render(request,'user/user_list.html',{'data_list':data_list})
def doDeleteUser(request):
    data = request.POST.dict()
    print(data)
    UserMsg.objects.filter(id = data['id']).delete()
    return JsonResponse({'msg':"删除成功",'code':200})
def doSearchUser(request):
    data = request.POST.dict()
    keywords_name = data['keywords_name']
    keywords_value = data['keywords_value']
    searchdata = {f'{keywords_name}__icontains': keywords_value}
    data_list = UserMsg.objects.filter(**searchdata)
    return JsonResponse({'msg':"查询成功",'data':serializers.serialize("json",data_list),'code':200})
